package com.yike.user.controller;

import com.yike.user.param.*;
import com.yike.user.service.ShopService;
import com.yike.user.vo.*;
import lombok.extern.slf4j.Slf4j;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺表 控制器
 *
 * @author Sakura
 * @since 2024-08-23
 */
@Slf4j
@RestController
@RequestMapping("/shop")
@Module("user")
@Api(value = "店铺管理API", tags = {"店铺管理"})
public class ShopController extends BaseController {

    @Autowired
    private ShopService shopService;

    /**
     * 添加店铺表
     */
    @PostMapping("/createUserShop")
    @OperationLog(name = "商户创建店铺", type = OperationLogType.ADD)
    @ApiOperation(value = "商户创建店铺", response = ApiResult.class)
    public ApiResult<Boolean> createUserShop(@Validated(Add.class) @RequestBody ShopParam shopParam) throws Exception {
        boolean flag = shopService.saveShop(shopParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/createAgentShop")
    @OperationLog(name = "代理商创建店铺", type = OperationLogType.ADD)
    @ApiOperation(value = "代理商创建店铺", response = ApiResult.class)
    public ApiResult<Boolean> createAgentShop(@Validated @RequestBody AgentCreateShopParam agentCreateShopParam) throws Exception {
        boolean flag = shopService.createAgentShop(agentCreateShopParam);
        return ApiResult.result(flag, "创建店铺成功");
    }

    /**
     * 修改店铺表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改店铺信息", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改店铺信息", response = ApiResult.class)
    public ApiResult<Boolean> updateShop(@Validated(Update.class) @RequestBody ShopParam shopParam) throws Exception {
        boolean flag = shopService.updateShop(shopParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除店铺表
     */
    @PostMapping("/delete/{shopNo}")
    @OperationLog(name = "删除店铺", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除店铺", response = ApiResult.class)
    public ApiResult<Boolean> deleteShop(@PathVariable("shopNo") String shopNo) throws Exception {
        boolean flag = shopService.deleteShop(shopNo);
        return ApiResult.result(flag);
    }

    /**
     * 获取店铺表详情
     */
    @GetMapping("/info/{shopNo}")
    //@OperationLog(name = "店铺详情", type = OperationLogType.INFO)
    @ApiOperation(value = "店铺详情", response = ShopVo.class)
    public ApiResult<ShopVo> getShop(@PathVariable("shopNo") String shopNo) throws Exception {
        ShopVo shopVo = shopService.getShop(shopNo);
        return ApiResult.ok(shopVo);
    }

    /**
     * 店铺表分页列表
     */
    @PostMapping("/getUserShopList")
    //@OperationLog(name = "商户店铺列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "商户店铺列表", response = ShopVo.class)
    public ApiResult<Paging<ShopVo>> getUserShopList(@Validated @RequestBody ShopPageParam shopPageParam) throws Exception {
        Paging<ShopVo> paging = shopService.getUserShopList(shopPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getAgentShopList")
    //@OperationLog(name = "代理商店铺列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "代理商店铺列表", response = ShopVo.class)
    public ApiResult<Paging<ShopVo>> getAgentShopList(@Validated @RequestBody ShopPageParam shopPageParam) throws Exception {
        Paging<ShopVo> paging = shopService.getAgentShopList(shopPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getAgentCreateShopList")
    //@OperationLog(name = "代理新建商店铺列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "代理新建商店铺列表", response = ShopVo.class)
    public ApiResult<Paging<ShopVo>> getAgentCreateShopList(@Validated @RequestBody ShopPageParam shopPageParam) throws Exception {
        Paging<ShopVo> paging = shopService.getAgentCreateShopList(shopPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getSubAgentShopList")
    //@OperationLog(name = "下级代理商店铺列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "下级代理商店铺列表", response = ShopVo.class)
    public ApiResult<Paging<ShopVo>> getSubAgentShopList(@Validated @RequestBody SubAgentShopPageParam subAgentShopPageParam) throws Exception {
        Paging<ShopVo> paging = shopService.getSubAgentShopList(subAgentShopPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/scanCode")
    //@OperationLog(name = "扫码获取店铺信息", type = OperationLogType.INFO)
    @ApiOperation(value = "扫码获取店铺信息", response = ShopVo.class)
    public ApiResult<ShopVo> scanCode(@Validated @RequestBody ScanShopCodeParam scanShopCodeParam) throws Exception {
        ShopVo shopVo = shopService.scanCode(scanShopCodeParam);
        return ApiResult.ok(shopVo);
    }

    @PostMapping("/choose/{shopNo}")
    @OperationLog(name = "选择店铺", type = OperationLogType.OTHER)
    @ApiOperation(value = "选择店铺", response = ShopVo.class)
    public ApiResult<ShopVo> chooseShop(@PathVariable("shopNo") String shopNo) throws Exception {
        ShopVo shopVo = shopService.chooseShop(shopNo);
        return ApiResult.ok(shopVo);
    }

    @PostMapping("/getAroundShopList")
    //@OperationLog(name = "获取周围店铺列表", type = OperationLogType.INFO)
    @ApiOperation(value = "获取周围店铺列表", response = ShopVo.class)
    public ApiResult<List<ShopVo>> getAroundShopList(@Validated @RequestBody AroundShopParam aroundShopParam) throws Exception {
        List<ShopVo> shopVos = shopService.getAroundShopList(aroundShopParam);
        return ApiResult.ok(shopVos);
    }

    @GetMapping("/getCloudGarrisonFlag")
    //@OperationLog(name = "获取店铺云驻守状态", type = OperationLogType.OTHER)
    @ApiOperation(value = "获取店铺云驻守状态", response = ApiResult.class)
    public ApiResult<Boolean> getCloudGarrisonFlag() throws Exception {
        boolean flag = shopService.getCloudGarrisonFlag();
        return ApiResult.ok(flag);
    }

    @PostMapping("/setCloudGarrisonFlag")
    @OperationLog(name = "设置店铺云驻守状态", type = OperationLogType.OTHER)
    @ApiOperation(value = "设置店铺云驻守状态", response = ApiResult.class)
    public ApiResult<Boolean> setCloudGarrisonFlag(@Validated @RequestBody SetCloudGarrisonFlagParam setCloudGarrisonFlagParam) throws Exception {
        boolean flag = shopService.setCloudGarrisonFlag(setCloudGarrisonFlagParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/shopBinding")
    @OperationLog(name = "店铺绑定申请", type = OperationLogType.ADD)
    @ApiOperation(value = "店铺绑定申请", response = ApiResult.class)
    public ApiResult<Boolean> shopBinding(@Validated @RequestBody ShopBindingParam shopBindingParam) throws Exception {
        boolean flag = shopService.shopBinding(shopBindingParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/getShopBindingList")
    //@OperationLog(name = "店铺绑定申请列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "店铺绑定申请列表", response = ShopBindingVo.class)
    public ApiResult<Paging<ShopBindingVo>> getShopBindingList(@Validated @RequestBody ShopBindingPageParam shopBindingPageParam) throws Exception {
        Paging<ShopBindingVo> paging = shopService.getShopBindingList(shopBindingPageParam);
        return ApiResult.ok(paging);
    }

    @GetMapping("/getShopBinding/{applyId}")
    //@OperationLog(name = "店铺绑定申请详情", type = OperationLogType.INFO)
    @ApiOperation(value = "店铺绑定申请详情", response = ShopBindingVo.class)
    public ApiResult<ShopBindingVo> getShopBinding(@PathVariable("applyId") Long applyId) throws Exception {
        ShopBindingVo shopBindingVo = shopService.getShopBinding(applyId);
        return ApiResult.ok(shopBindingVo);
    }

    @PostMapping("/checkShopBinding")
    @OperationLog(name = "店铺绑定审核", type = OperationLogType.OTHER)
    @ApiOperation(value = "店铺绑定审核", response = ShopBindingVo.class)
    public ApiResult<Boolean> checkShopBinding(@Validated @RequestBody CheckShopBindingParam checkShopBindingParam) throws Exception {
        boolean flag = shopService.checkShopBinding(checkShopBindingParam);
        return ApiResult.result(flag);
    }

    @PostMapping("/adjustPrice")
    @OperationLog(name = "一键调价", type = OperationLogType.OTHER)
    @ApiOperation(value = "一键调价", response = ApiResult.class)
    public ApiResult<Boolean> adjustPrice(@Validated @RequestBody AdjustPriceParam adjustPriceParam) throws Exception {
        boolean flag = shopService.adjustPrice(adjustPriceParam);
        return ApiResult.result(flag);
    }

    @GetMapping("/getShopAdjustPrice")
    //@OperationLog(name = "获取店铺一键调价信息", type = OperationLogType.INFO)
    @ApiOperation(value = "获取店铺一键调价信息", response = AdjustPriceVo.class)
    public ApiResult<AdjustPriceVo> getShopAdjustPrice() throws Exception {
        AdjustPriceVo adjustPriceVo = shopService.getShopAdjustPrice();
        return ApiResult.ok(adjustPriceVo);
    }

    @PostMapping("/getShopDataStatistics")
    //@OperationLog(name = "获取店铺数据统计", type = OperationLogType.INFO)
    @ApiOperation(value = "获取店铺数据统计", response = ShopDataStatisticsVo.class)
    public ApiResult<ShopDataStatisticsVo> getShopDataStatistics(@Validated @RequestBody ShopDataStatisticsParam shopDataStatisticsParam) throws Exception {
        ShopDataStatisticsVo shopDataStatisticsVo = shopService.getShopDataStatistics(shopDataStatisticsParam);
        return ApiResult.ok(shopDataStatisticsVo);
    }

    @PostMapping("/getShopGarrisonDataList")
    //@OperationLog(name = "店铺值守数据列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "店铺值守数据列表", response = ShopGarrisonDataVo.class)
    public ApiResult<Paging<ShopGarrisonDataVo>> getShopGarrisonDataList(@Validated @RequestBody ShopGarrisonDataPageParam shopGarrisonDataPageParam) throws Exception {
        Paging<ShopGarrisonDataVo> paging = shopService.getShopGarrisonDataList(shopGarrisonDataPageParam);
        return ApiResult.ok(paging);
    }

}

